% % % This script produces the figures and tables in the main text of the article
% % % "The dynamic impact of FX interventions on financial markets" by Lukas Menkhoff, Malte Rieth and Tobias St�hr.
% % % 
% % % There are several scripts that are run as well as functions. The latter have the pre-fix zFC_* and need to be placed
% % % in the same folder as this Read_and_run_me.m-file.
% % % 
% % % Written: Malte Rieth, DIW Berlin, April 2020

clc
clear
close all

%% General settings for figures, model etc.

save_figures = 0;
cholesky_on = 0 ;
winsorize_on = 0 ;
bootstrap_on = 1 ;
font_size = 9 ;
T_irf = 150;  % horizons of the IRFs
sd_shock = 1 ;
shock_size = 1 ; 
p =50;
exogD       = 0;
fevd_on = 0 ;
hd_on = 0 ;

grey  = [0.8,0.8,0.8]-0.3; 
red   = [0.6,0.1,0.2];
blue  = [0.25,0.3,0.8]+0.1;

Loops           = 10 ;

load fx_interventions_MRS2020;
assert( size(data_all,1) ==  length(year))
assert( size(data_all,1) ==  length(month))
assert( size(data_all,1) ==  length(day))

%% Figure 1: Interventions and instrument

choose_variab = [1:8]; % use variables in main model to restrict sample appropriately 
% choose_shock=[165 189]   ; % pick two lines to be plotted
choose_shock=[11,12]   ; % pick two lines to be plotted
choose_exog = [16:30 ] ; %    choose exogenous

Figure_1_interventions_and_instruments

%% Figure 2: The dynamic effects of FX intervention shocks in Japan

rows_fig = 2 ;
cols_fig = 1 ;
T_irf = 250; 

% bivariate SVAR
choose_variab = [1,2]; % small
choose_shock=[ 12]   ; % baseline 5-day window
choose_exog = [16:30 ] ; 

Figures_effects_FX_intervention_Japan

%% Figure 3: Effects of FX intervention shocks in Japan on other currencies

rows_fig = 2 ;
cols_fig = 2 ;
T_irf = 100;  

% four-variable SVAR
choose_variab = [1,2,9,10]; 

Figures_effects_FX_intervention_Japan

%% Figure 4: Responses of interest rates and stock prices to JPY-intervention shock
%  Table 3: Forecast error variance decomposition
%  Figure 5: Historical decomposition of USD/JPY exchange rate and estimated intervention shocks

rows_fig = 4 ;
cols_fig = 2 ;
T_irf = 100;  
fevd_on = 0 ;
hd_on = 0 ;

% eight-variable SVAR
choose_variab = [1:8];

Figures_effects_FX_intervention_Japan

%% Figure 6: Subsample estimates

rows_fig = 2 ;
cols_fig = 1 ;
T_irf = 250;          % horizons of the IRFs
shock_size = 9.3477 ; % shock size USD bn
sd_shock = 0 ;

choose_variab = [1,2]; % small

Figure_6_subsamples

%% Figure 7: Technical decomposition of transmission channels

rows_fig = 4 ;
cols_fig = 2 ;
T_irf = 100;  
sd_shock = 0 ;
shock_size =1 ; 
Loops           = 2 ;
cholesky_on = 1 ;
bootstrap_on = 1 ;

choose_variab = [1:8];

Figure_7_technical_decomposition

%% Figure 8: Narrative decomposition of transmission channels

choose_variab = [1:8]; % extended 

Figure_8_narrative_decomposition